﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// 比赛列表
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class list : view<list>
    {
        /// <summary>
        /// 分页连接
        /// </summary>
        private static readonly string pagePath = diantou.dataModel.path.pub.Default.ContestListPath + "?type=";
        /// <summary>
        /// 比赛列表
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private userContest[] contests;

        /// <summary>
        /// 初始化问题列表
        /// </summary>
        /// <param name="page">分页号</param>
        /// <returns>是否成功</returns>q
        private bool loadView(diantou.dataAccess.contest.getType type, int page)
        {
            diantou.dataAccess.contest[] values;
            if (type == dataAccess.contest.getType.Self && currentUser == null) type = dataAccess.contest.getType.All;
            if (type == dataAccess.contest.getType.Self)
            {
                if (diantou.dataAccess.clientCache.ContestRegister.IsData)
                {
                    subArray<int> contestIds = contestRegister.Default.GetContestIds(currentUserId).toSubArray();
                    pageInfo.Count = contestIds.Count;
                    values = diantou.dataAccess.clientCache.Contest.Get(contestIds.GetPageDesc(pageInfo.Size = 20, pageInfo.Page = page));
                }
                else values = diantou.dataAccess.clientCache.Contest.Get(diantou.dataAccess.tcpCall.focusContest.getFocusIds(currentUserId, dataModel.focus.type.Register, pageInfo.Size = 20, pageInfo.Page = page, out pageInfo.Count));
            }
            else
            {
                values = diantou.dataAccess.clientCache.Contest.Get(diantou.dataAccess.tcpCall.contest.getIds(type, pageInfo.Size = 20, pageInfo.Page = page, currentUserId, currentUser != null && currentUser.IsChangeVisit, out pageInfo.Count));
                if (requestHeader.IsSearchEngine) pageInfo.Path = pagePath + type.ToString();
            }
            contests = values.getArray(value => new userContest { Contest = value, User = currentUser });
            return true;
        }
    }
}
